package org.xempot.example;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import org.xempot.xform.Transform;
/**
 * Basic example demonstrating 3 html outputs
 * @author brook
 *
 */
public class HtmlExample {

	public static void main(String[] args) {
		setup();
		
		InputStream testStream = ClassLoader.getSystemResourceAsStream("exampledata/Food_xform_3.xml");
		if (testStream == null) {
			throw new NullPointerException("Cannot load example data: exampledata/Food_xform_3.xml");
		}
		
		try {
			Transform transform = new Transform(ClassLoader.getSystemResourceAsStream("exampledata/Food_xform_3.xml"),
					new FileOutputStream("example/food_2.html"),
					ClassLoader.getSystemResourceAsStream("exampledata/Food.xml"));

			transform.process();
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			Transform transform = new Transform(ClassLoader.getSystemResourceAsStream("exampledata/Food_xform.xml"),
					new FileOutputStream("example/food.html"),
					ClassLoader.getSystemResourceAsStream("exampledata/Food.xml"));

			transform.process();
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			Transform transform = new Transform(ClassLoader.getSystemResourceAsStream("exampledata/template.xml"),
					new FileOutputStream("example/template.html"),
					ClassLoader.getSystemResourceAsStream("exampledata/template_data.xml"));

			transform.process();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private static void setup() {
		File f = new File("example");
		if (!f.exists()) {
			f.mkdirs();
			f.mkdir();
		}
	}

}
